from typing import List


class Solution:
    def reductionOperations(self, nums: List[int]) -> int:
        nums.sort()
        ans = 0
        now = nums[0]
        count = 0
        for num in nums:
            if num > now:
                now = num
                count += 1
            ans += count
        return ans


if __name__ == "__main__":
    print(Solution().reductionOperations(nums=[5, 1, 3]))  # 3
    print(Solution().reductionOperations(nums=[1, 1, 1]))  # 0
    print(Solution().reductionOperations(nums=[1, 1, 2, 2, 3]))  # 4
